package com.emex.app.stuff.provider;

import com.emex.app.shared.data.Provider;
import com.emex.app.shared.ws.ProviderWebService;
import com.emex.app.stuff.utils.WebServiceHelper;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;

/**
 *
 * @author Sergey Karavaev
 */
public class ProviderDataProvider extends Service {

    private ProviderWebService service = null;

    private static ProviderDataProvider instance = null;

    /**
     * Constructor
     */
    private ProviderDataProvider() throws MalformedURLException {
        super(new URL(WebServiceHelper.getDefault().getWebServiceURL("web", "Provider")),
                WebServiceHelper.getDefault().getWebServiceQName("Provider"));
        service = getPort(ProviderWebService.class);
    }

    /**
     * Get instance of data provider.
     *
     * @return data provider instance
     */
    public static synchronized ProviderDataProvider getInstance() {
        if (instance == null) {
            new RequestWebService() {
                @Override
                protected void doRequestBody() throws MalformedURLException {
                    instance = new ProviderDataProvider();
                }
            }.doRequest();
        }
        return instance;
    }

    public BindingProvider getBindingProvider() {
        return (BindingProvider) service;
    }

    public int deleteProviderByPrimaryKey(Integer id) {
        return service.deleteProviderByPrimaryKey(id);
    }

    public Provider insertProvider(Provider record) {
        return service.insertProvider(record);
    }

    public List<Provider> getAllProviders() {
        return service.getAllProviders();
    }

    public Provider updateProvider(Provider record) {
        return service.updateProvider(record);
    }

    public Provider selectProviderByPrimaryKey(Integer id) {
        return service.selectProviderByPrimaryKey(id);
    }
}